<template>
    <div id="global-bar-user-container">
        <Global_Guide_Item :mainMenus="getLoginMenus()" class="CItem" v-if="isEntry()"/>
        <Global_Guide_Item :mainMenus="getUserMenus()" class="CItem" v-else/>
    </div>
</template>

<script>

import Global_Guide_Item from "@guide/vue/item";
import local_vuex from "@guide/js/vuex";

export default {
    components: {
        Global_Guide_Item
    },
    methods: {
        /**
         * 获取 "用户" 菜单
         */
        getUserMenus() {
            return local_vuex.state.userMenus;
        },
        /**
         * 获取 "登录" 菜单
         */
        getLoginMenus() {
            return local_vuex.state.loginMenus;
        },
        /**
         * 判断当前要显示的是 "登录" 菜单还是 "用户" 菜单
         *  - 有用户登录时：设置欢迎词，并返回 `false`，显示 "用户" 菜单
         *  - 没有用户登录时：直接返回 `true`，显示 "登录" 菜单
         */
        isEntry() {
            if (this.$store.state.user.sid === '') {
                return true
            } 
            else {
                local_vuex.state.userMenus[0].context = "欢迎你，" + this.$store.state.user.name
                return false
            }
        }
    }
}
</script>

<style lang="scss">
@import "@guide/scss/user.scss";
</style>